<!--
 * @description 超链接组件
 * @author: 陈陈
 * @date: 2025/05/09
 * @phone: 18560000860
 * @email: 18560000860@qq.com
 * @company: 济南晨霜信息技术有限公司 /
 * @business: 承接前后端项目的开发
-->
<template>
	<view
		class="pure-link"
		:class="_classes"
		:style="_styles"
		:hover-class="hoverClass"
		@click="_handleClick"
	>
		<!-- 前置图标 -->
		<view
			class="pure-link__icon pure-link__icon--before"
			v-if="beforeIconName"
		>
			<pure-icon :name="beforeIconName"></pure-icon>
		</view>

		<!-- 文本 -->
		<view
			class="pure-link__text"
			v-if="text || $slots.default"
		>
			<slot>{{ text }}</slot>
		</view>

		<!-- 后置图标 -->
		<view
			class="pure-link__icon pure-link__icon--after"
			v-if="afterIconName"
		>
			<pure-icon :name="afterIconName"></pure-icon>
		</view>
	</view>
</template>

<script>
	import commonComponentOptions from "../../config/options";
	export default {
		options: commonComponentOptions
	};
</script>

<script setup>
	import { computed } from "vue";
	import props from "./props";
	import { getThemeValue } from "../../utils";

	// -------------------------------------------------------------------------------- Props
	const _props = defineProps(props);

	// -------------------------------------------------------------------------------- Emits
	const _emits = defineEmits(["onClick"]);

	// -------------------------------------------------------------------------------- Classes
	const _classes = computed(() => {
		const array = [];

		// 主题
		if (_props.theme) array.push(`pure-link--theme pure-link--theme--${_props.theme}`);

		// 下划线
		if (_props.underline) array.push("pure-link--underline");

		// 是否禁用
		if (_props.disabled) array.push("pure-link--disabled");

		return array;
	});

	// -------------------------------------------------------------------------------- Styles
	const _styles = computed(() => {
		const array = [];

		// 主题
		if (_props.theme) array.push(`--pure-link-theme: ${getThemeValue(_props.theme)}`);

		return array;
	});

	// 点击事件
	function _handleClick() {
		if (_props.disabled) return;
		_emits("onClick");
	}
</script>

<style scoped lang="scss">
	@import "./style.scss";
</style>
